<?php

class Core_Action_Admin_System_I18n_Language_Add extends Action_Admin
{
	public function execute($request, $initial = false, $script = null)
	{
		if ($initial)
		{
			Agilet::setVar('breadcrum', array(
				array(
					'url' => 'admin/system',
					'label' => 'System'
				),
				array(
					'url' => 'admin/system/i18n',
					'label' => 'International'
				),
				array(
					'url' => 'admin/system/i18n/language',
					'label' => 'Language'
				),
				array(
					'url' => 'admin/system/i18n/language/edit',
					'label' => 'Add Language'
				)
			));
		}

		$table = Model::getTable('core/i18n/language');

		$form = Form::factory('core/admin/i18n/language');

		if ($request -> isPost() and $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$item = $table -> fetchNew();
			$item -> fromArray($data);
			$item -> save();

			/**
			 * redirect to mangae language page.
			 */
			Response::initiator() -> redirect('admin/system/i18n/language');
		}

		$request -> response = View::render($script = 'core/html/admin/edit', $data = array(
			'form' => $form,
			'title' => 'Add Language'
		));
	}

}
